package cn.jiangjiesheng.bootstrap.database;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * Created by dev@jiangjiesheng.cn on 2021/9/3  <br/>
 *
 * @author dev@jiangjiesheng.cn
 */
@Configuration
@AutoConfigureAfter(value = MyDataSourceAutoConfiguration.class)
public class MyJdbcTemplateAutoConfiguration {

    @Primary
    @Bean(name = "jdbcTemplateOne")
    @ConditionalOnBean(name = "dataSourceOne")
    public JdbcTemplate jdbcTemplateOne(@Qualifier("dataSourceOne") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    @Bean(name = "jdbcTemplateTwo")
    @ConditionalOnBean(name = "dataSourceTwo")
    public JdbcTemplate jdbcTemplateTwo(@Qualifier("dataSourceTwo") DataSource dataSource) {
        return new JdbcTemplate(dataSource, true);
    }

    @Bean(name = "jdbcTemplateThree")
    @ConditionalOnBean(name = "dataSourceThree")
    public JdbcTemplate jdbcTemplateThree(@Qualifier("dataSourceThree") DataSource dataSource) {
        return new JdbcTemplate(dataSource, true);
    }
}
